<%@page import="News.dao.Page"%>
<%@page import="News.service.impl.Inland_NewsServiceImpl"%>
<%@page import="News.service.Inland_NewsService"%>
<%@page import="News.entity.Inland_News"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
  <body>
  <script type="text/javascript"></script>
  <style type="text/css">
  #juzhong{
  background:#D9EBF5;
  text-align:center;
  list-style-type:none
  }
  
  </style>
  
  	 <table border="1" align="center" width="500">
  		<tr align="center">
  			<td>新闻编号</td>
  			<td>新闻内容</td>
  			<td>发布时间</td>
  			<td>浏览人数</td>
  			<td colspan="2">操作</td>
  		</tr>
  		<%
  		session.getAttribute("newsList");
  		
  		String currentPage = request.getParameter("pageIndex");
	  		if(currentPage ==null){
	  			//用户首次访问页面
	  			currentPage="1";
	  		}
  		//当前页码
  		int pageIndex =Integer.parseInt(currentPage);
  		//获取新闻总数量
  		Inland_NewsService newsService = new Inland_NewsServiceImpl();
  		int totalcount = newsService.getTotalCount();
  		//每页显示几条新闻
  		int pageSize =3;
  		//获取总页数
  		Page page2 = new Page();
  		page2.setCurrNo(pageIndex);
  		page2.setPageSize(pageSize);
  		page2.setTotalInfoCount(totalcount);
  		//拿到总页数
  		int zongyeshu = page2.getTotalPageCount();
  		
  		//控制首页和尾页
  		if(pageIndex<1){
  			pageIndex=1;
  		}else if(pageIndex>zongyeshu){ 
  			pageIndex = zongyeshu;
  		}
  		
  		List<Inland_News> InList  = newsService.getPageNewsList(pageIndex, pageSize);
  		for(Inland_News Inlist:InList){
			int newsid = Inlist.getNewsId();
			String newscont = Inlist.getNewsContent();
			String newstime = Inlist.getTime(); 
			int newsnor = Inlist.getNumOfRead(); 		
  		%>
  			<tr align="center">
		  		<td><%=newsid%></td>
		  		<td><%=newscont%></td>
		  		<td><%=newstime%></td>
		  		<td><%=newsnor%></td>
		  		<td>
		  		<!-- 这个地方传的newsid=你上边的id  然后一个请求传过去 opr是del （带着newsid）delid 意思就是要删除的id opr是键 他的值是“del”这是一个字符串-->
		  		<a href="/NewsPublish/InlandNewsServlet?opr=del&delid=<%=newsid%>">删除</a> 
		  		<%
		  		 session.setAttribute("del", newsid);//就又是一个流程  这就又都变了 虽然你上一个id没用到 再回到这 也是用不到 变成新的被覆盖了
		  		%>
		  		<a href="upInlandNews.jsp">修改</a>
		  		
		  		</td>
	  		</tr>
	  		
	  		
  		
  		<%
  		}
  		%>
  		
  		<form action="/NewsPublish/InlandNewsServlet?opr=add" method="post">
	  		<tr align="center">
	  			<td><input type="text" id="newsid" name="newsid"  value="新闻编号"></td>
	  			<td><input type="text" id="newscont" name="newscont" value="新闻内容"></td>
	  			<td><input type="text" id="newstime" name="newstime" value="发布时间"></td>
	  			<td><input type="text" id="newsnor" name="newsnor" value="访问人数"></td>
	  			<td><input type="submit" value="新增"></td>
	  		</tr>
	  		</form>
  		
  		
  		
  		</table>
  		<ul class="page-num-ul clearfix" id="juzhong">
  			<li>共<%=totalcount%>条记录&nbsp;&nbsp; <%=pageIndex%>/<%=zongyeshu%>页</li>
  			<%
  			if(pageIndex>1){
  			 %>
  			<a href="showInlandNews.jsp?pageIndex=1">首页</a>
  			<a href="showInlandNews.jsp?pageIndex=<%=pageIndex-1%>">上一页</a>
  			<% } if(pageIndex<zongyeshu){%>
  			<a href="showInlandNews.jsp?pageIndex=<%=pageIndex+1%>">下一页</a>
  			<a href="showInlandNews.jsp?pageIndex=<%=zongyeshu%>">尾页</a>
  			<%} %>
  		</ul>
  		<hr>
  		<div style = "text-align:center;">
  		<input type="button" value="返回" onclick="javascript:history.go(-1);">
  		</div>
  		
  </body>
  		
</html>


